import java.awt.Color;
import java.awt.Graphics;



public class ParticleBox{
	private int x = 0;
	private int y = 0;
	
	private int destX = 0;
	private int destY = 0;
	
	private double speedX = 0;
	private double speedY = 0;
	
	private int alpha = 255;
	private int red = 100;
	private int green = 100;
	private int blue = 100;
	private int width;
	private int height;
	private int thickness = 2;
	private int key;
	
	public ParticleBox(int width, int x, int y, double num, double numSibs){		
		this.x = x;
		this.y = y;
		this.destX = x;
		this.destY = y;
		this.key = (int)num;
		red = (int) (num)%150;
		green = (int) (num*num)%10;
		blue = (int) (num*num*num)%10;
		
		this.width = width;
		this.height = key*-1;
	}
	
    public void draw(Graphics g) {    
    	moveTowards();
    	g.setColor(new Color(red,green,blue,alpha));
    	g.fillRect(x, y, width, height);
    }
    
    public void dissappear(int rate){
    	int newAlpha = alpha - rate;
    	if(newAlpha>0){
    		alpha = newAlpha;
    	}else{
    		alpha = 0;
    	}    	
    }
    
    public int width(){
    	return width;
    }
    
    public int height(){
    	return height;
    }
    
    public static ParticleBox getBoxByNum(int newLocation, int num, ParticleBox[] array){
    	for(int i=0;i<array.length;i++){
    		if(array[i]!=null && array[i].key == num){
    			ParticleBox temp = array[i];
    			array[i] = array[newLocation];
    			array[newLocation] = temp;
    			return temp;
    		}
    	}
    	return null;
    }
    
    public void move(int newX, int newY, int width, int height){
    	this.destX = newX;
    	this.destY = newY;
    	this.width = width;
    	this.height = height;
    	
    }
    
    private void moveTowards(){      	
    	double dist = Math.sqrt(Math.pow(destX-x,2)+Math.pow(destY-y, 2));
  	    double speedX = (destX - x);
  	    double speedY = (destY - y);
  	    
  	    
    	if(x != destX){
	  	    x+=speedX;
    	}
    	if(y != destY){
    		y+=speedY;
    	}
    }
    
}
